import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:local_notifier/local_notifier.dart';
import 'package:palyer/app/components/toast_widget.dart';
import 'package:palyer/app/core/utils/log_util.dart';
import 'package:palyer/app/core/utils/windows_utils.dart';
import 'package:palyer/app/core/values/themes.dart';
import 'package:palyer/app/modules/home/home/states.dart';
import 'package:palyer/router/app_pages.dart';

class HomeController extends GetxController {
  final HomeStates states = HomeStates();

  final List<String> text = [
    '关关雎鸠，在河之洲',
    '窈窕淑女，君子好逑',
    '参差荇菜，左右流之',
    '窈窕淑女，寤寐求之',
    '求之不得，寤寐思服',
    '悠哉悠哉，辗转反侧',
    '参差荇菜，左右采之',
    '窈窕淑女，琴瑟友之',
    '参差荇菜，左右芼之',
    '窈窕淑女，钟鼓乐之',
  ];

  final List<String> text2 = [
    '相见时难别亦难，东风无力百花残',
    '春蚕到死丝方尽，蜡炬成灰泪始干',
    '晓镜但愁云鬓改，夜吟应觉月光寒',
    '蓬山此去无多路，青鸟殷勤为探看',
  ];

  // 侧边栏
  final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();


  @override
  void onInit() {
    super.onInit();
    init();
  }


  // 跳转播放页
  void goPlay() {
    Get.toNamed(AppRoutes.play);
  }

  // 跳转文件拖动
  void goDrop() {
    Get.toNamed(AppRoutes.drop);
  }

  // 跳转系统托盘
  void goTray() {
    Get.toNamed(AppRoutes.tray);
  }

  // 检查更新
  void checkUpdate() {
    AppToast.showSuccess('已是最新版本');
  }

  // 主题切换
  void changeTheme() {
    Get.changeTheme(
      Get.isDarkMode ? appThemeData : appThemeDataDark,
    );
  }

  // unity
  void goExcel() {
    Get.toNamed(AppRoutes.excel);
  }

  // 初始化通知
  init() async {
    // Add in main method.
    await localNotifier.setup(
      appName: 'local_notifier_example',
      // The parameter shortcutPolicy only works on Windows
      shortcutPolicy: ShortcutPolicy.requireCreate,
    );
  }

  // 通知
  void showNotification() async {
    // LocalNotifier.instance.setAppName("fuck you");
    final LocalNotification notification = LocalNotification(
      title: '你爹来了',
      body: text2.join('.'),
      actions: [
        LocalNotificationAction(text: '你妈在吗', type: '1'),
        LocalNotificationAction(
          text: '你爸',
          type: '2',
        ),
        LocalNotificationAction(
          text: '你爸爸',
          type: '3',
        ),
      ],
      subtitle: '我是你爸爸',
    );

    notification.onShow = () {
      AppLogger.devLog('onShow ${notification.identifier}');
    };
    // notification.onClose = () {
    //   print('onClose ${notification.identifier}');
    // };
    notification.onClick = () {
      AppToast.showSuccess(notification.body.toString());
    };
    notification.onClickAction = (actionIndex) {
      AppToast.showSuccess('onClickAction ${notification.body} - $actionIndex');
    };

    notification.show();
  }

  settingFull() {
    WindowsUtils.settingFull();
  }

  // 最小化
  min() {
    WindowsUtils.minimize();
  }

  // 退出
  exit() {
    WindowsUtils.close();
  }

  // 置顶
  top() {
    WindowsUtils.setTop();
  }

  // 退出登录
  void logout() {
    Get.offAllNamed(AppRoutes.authLogin);
  }


}
